You may find it most helpful to compare the full programs using xdiff or a similar tool. This section briefly points out the main differences between two example programs.
work_animate: static Boolean redraw_proc(XtPointer clientData);
time_animate: static Boolean redraw_proc(XtPointer clientData,
XtIntervalId *id);
#define TIMEOUT 10 /*timeout in milliseconds*/
work_animate:
static struct { /* global UI variables; keep them together */
XtAppContext appctx;
Widget glxwidget;
Boolean direct;
XtWorkProcId animate_wpid;
} state;
time_animate:
static struct { /* global UI variables; keep them together */
XtAppContext appctx;
Widget glxwidget;
Boolean direct;
XtIntervalId animate_toid;
} state;
work_animate:
static void
menu(Widget w, XtPointer clientData, XtPointer callData) {
int entry = (int) clientData;
switch (entry) {
case 0:
if (state.animate_wpid) {
XtRemoveWorkProc(state.animate_wpid);
state.animate_wpid = 0;
} else {
/* register work proc */
state.animate_wpid = XtAppAddWorkProc(state.appctx,
redraw_proc, &state.glxwidget);
}
break;
case 1:
exit(EXIT_SUCCESS);
break;
default:
break;
}
}
time_animate
static void
menu(Widget w, XtPointer clientData, XtPointer callData) {
int entry = (int) clientData;
switch (entry) {
case 0:
if (state.animate_toid) {
XtRemoveTimeOut(state.animate_toid);
state.animate_toid = 0;
} else {
/* register timeout */
state.animate_toid = XtAppAddTimeOut(state.appctx,
TIMEOUT, redraw_proc, &state.glxwidget);
}
break;
case 1:
exit(EXIT_SUCCESS);
break;
default:
break;
}
}
static void
redraw_proc(XtPointer clientData, XtIntervalId *id) {
Widget *w = (Widget *)clientData;
draw_scene(*w);
/* register a new timeout */
state.animate_toid = XtAppAddTimeOut(state.appctx, TIMEOUT,
redraw_proc, &state.glxwidget);
}